package com.carbon.assets.controller;

import com.carbon.assets.service.CarbonExchangeService;
import com.carbon.assets.param.CarbonExchangeQueryParam;
import com.carbon.domain.assets.vo.CarbonExchangeQueryVo;
import com.carbon.assets.entity.CarbonExchange;
import com.carbon.assets.common.BaseController;
import com.carbon.common.api.Paging;
import com.carbon.domain.common.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * <p>
 * 碳交易所  前端控制器
 * </p>
 *
 * @author Li Jun
 * @since 2021-08-16
 */
@Slf4j
@RestController
@RequestMapping("/carbonExchange")
@Api(value = "碳交易所 模块", tags = {"碳交易所 模块"})
public class CarbonExchangeController extends BaseController {

    @Autowired
    private CarbonExchangeService carbonExchangeService;

    /**
     * 获取碳交易所
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "获取交易所详情", notes = "查看碳交易所")
    public ApiResult<CarbonExchangeQueryVo> getCarbonExchange(@PathVariable Long id) {
        CarbonExchangeQueryVo carbonExchangeQueryVo = carbonExchangeService.getCarbonExchangeById(id);
        return ApiResult.ok(carbonExchangeQueryVo);
    }

    /**
     * 碳交易所分页列表(可带条件查询)
     */
    @PostMapping("/getPageList")
    @ApiOperation(value = "获取交易所分页列表(可带条件查询)", notes = "碳交易所分页列表")
    public ApiResult<Paging<CarbonExchangeQueryVo>> getCarbonExchangePageList(@Valid @RequestBody(required = false) CarbonExchangeQueryParam carbonExchangeQueryParam) {
        Paging<CarbonExchangeQueryVo> paging = carbonExchangeService.getCarbonExchangePageList(carbonExchangeQueryParam);
        return ApiResult.ok(paging);
    }

    /**
     * 修改碳交易所
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改交易所", notes = "修改碳交易所")
    public ApiResult<Boolean> updateCarbonExchange(@Valid @RequestBody CarbonExchange carbonExchange) {
        boolean flag = carbonExchangeService.updateById(carbonExchange);
        return ApiResult.result(flag);
    }

    /**
     * 删除碳交易所
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除交易所", notes = "删除碳交易所")
    public ApiResult<Boolean> deleteCarbonExchange(@PathVariable Long id) {
        boolean flag = carbonExchangeService.removeById(id);
        return ApiResult.result(flag);
    }
}

